package com.acme.bankapp.domain.bank.accounts;

import com.acme.bankapp.domain.bank.exceptions.NotEnoughFundsException;

@SuppressWarnings("serial")
public abstract class AbstractAccount implements Account {

	protected double balance;
	
	protected AbstractAccount(double initialBalance) {
		if (initialBalance < 0) throw new IllegalArgumentException();
		balance = initialBalance;
	}
	
	public void deposit(double x) {
		balance += x;
	}

	public void withdraw(double x) throws NotEnoughFundsException {
		if (balance >= x) {
			balance -= x;
		} else {
			throw new NotEnoughFundsException(x - balance);
		}
	}

	public double getBalance() {
		return balance;
	}

	@Override
	public String toString() {
		return "Account [balance=" + balance + "]";
	}

	@Override
	public boolean equals(Object acc) {
		return this == acc;
	}
	
	@Override
	public int hashCode() {
		return super.hashCode();
	}
	
	@Override
	public long decimalValue() {
		return Math.round(balance);
	}
}
